#!/usr/bin/env python
# -*- coding:utf-8 -*-

import os, sys

cldir = "../closure-library-read-only/"
cprdir = "../closure-library-read-only/compiler/"
jsdir = "static/"
builderPath = "%s/closure/bin/build/closurebuilder.py" % cldir
root1 = "--root=%s" % cldir
root2 = "--root=%s" % jsdir
namespace = '--namespace="poosip.editor"'
output_mode = '--output_mode=compiled'
compile_jar = '--compiler_jar=%s/compiler.jar' % cprdir
compiler_flags = '--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS"'
output_file = '--output_file=%s%s' % (jsdir, "editor-compiled.js")

def usage():
  print("Usage:")
  print("$ python build.py dep")
  print("$ python build.py cp")
  print("$ python build.py cpadv")

if __name__ == '__main__':
  if len(sys.argv) != 2:
    usage()
    sys.exit(1)

  if sys.argv[1] == "dep":
    os.system('%s %s %s %s' 
              % (builderPath, root1, root2, namespace))
    sys.exit(0)
  elif sys.argv[1] == "cp":
    os.system('%s %s %s %s %s %s %s' 
              % (builderPath, root1, root2, namespace, output_mode, compile_jar, output_file))
    sys.exit(0)
  elif sys.argv[1] == "cpadv":
    os.system('%s %s %s %s %s %s %s %s' 
              % (builderPath, root1, root2, namespace, output_mode, compile_jar, compiler_flags, output_file))
    sys.exit(0)
  else:
    usage()
    sys.exit(1)
